-
Notifications
You must be signed in to change notification settings - Fork 32
Disallow scalar conversation for non-0D arrays #2223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
View rendered docs @ https://intelpython.github.io/dpctl/pulls/2223/index.html |
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_103 ran successfully. |
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_108 ran successfully. |
| cdef inline void _check_0d_scalar_conversion(object usm_ary) except *: | ||
| "Raise TypeError if array cannot be converted to a Python scalar" | ||
| if (usm_ary.ndim != 0): | ||
| raise TypeError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| raise TypeError( | |
| raise ValueError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess NumPy raises a TypeError but this really seems like a ValueError to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usm_ary.ndim != 0 means the object is not scalar-like and does not implement the scalar conversional protocol so TypeError is more appropriate than ValueError
ndgrigorian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aside from minor comments this LGTM
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_109 ran successfully. |
|
Array API standard conformance tests for dpctl=0.22.0dev0=py310h93fe807_110 ran successfully. |
This PR aligns
usm_ndarrayscalar conversion semantics with the Python Array API by allowing scalar conversion only for 0D usm_ndarraysConversions to Python numeric scalars via
int,float,complex,bool, and their corresponding methods (__int__,_float__,__complex__, bool) now raiseTypeErrorwhen applied to usm_ndarrays withndim !=0`